#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > energy_srpbe_mp2.info <<'%EOF%'
   energy_srpbe_mp2
   ----------------
   Molecule:         H2O
   Wave Functions:   SCF, MP2
   Test Purpose:     Check srDFT energy calculations
                     with symmetry, with GGA (PBE), with erf 0.4,
                     with test MP2 with short-range integrals
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > energy_srpbe_mp2.mol <<'%EOF%'
ATOMBASIS
NEVPT2-srDFT Energy calculation with symmetry
Basis set specified with ATOMBASIS
    2     
        8.    1      Basis=cc-pVDZ
O     0.0 -0.2249058930 0.0
        1.    2      Bas=cc-pVDZ
H1    1.45235 0.899623 0.0
H2   -1.45235 0.899623 0.0
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > energy_srpbe_mp2.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTION
**INTEGRALS
*TWOINT
.DOSRINTEGRALS
.ERF
 0.4
**WAVE FUNCTIONS
.HFSRDFT
.MP2SRDFT
.SRFUN
SRXPBEHSE SRCPBERI
*SCF INPUT
.DOUBLY OCCUPIED
 3 1 1 0
*MP2 INPUT
.MP2 FROZEN
 2 0 0 0
.SRINTS 
**END OF INPUT
%EOF%
#######################################################################

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >energy_srpbe_mp2.check
cat >>energy_srpbe_mp2.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -i -a"
else
   GREP="egrep -i"
fi

# Reading ATOMBASIS:
CRIT1=`$GREP "\[9s4p1d\|3s2p1d\]" $log | wc -l`
TEST[1]=`expr $CRIT1`
CTRL[1]=1
ERROR[1]="ATOMBASIS NOT READ CORRECTLY"

# Reading molecular geometry:
CRIT1=`$GREP "1 * x * 0*\.0000000000" $log | wc -l`
CRIT2=`$GREP "2 * y * 0*\.0000000000" $log | wc -l`
CRIT3=`$GREP "3 * z * \-*0*\.125851" $log | wc -l`
CRIT4=`$GREP "4 * x * 0*\.0000000000" $log | wc -l`
CRIT5=`$GREP "5 * y * 1\.4523500000" $log | wc -l`
CRIT6=`$GREP "6 * z * 0*\.998677" $log | wc -l`
CRIT7=`$GREP "7 * x * 0*\.0000000000" $log | wc -l`
CRIT8=`$GREP "8 * y * \-1\.4523500000" $log | wc -l`
CRIT9=`$GREP "9 * z * 0*\.998677" $log | wc -l`
CRIT10=`$GREP "Total number of coordinates: * 9" $log | wc -l`
TEST[2]=`expr $CRIT1  \+ $CRIT2  \+ $CRIT3  \+ $CRIT4  \+ $CRIT5  \+ \
              $CRIT6  \+ $CRIT7  \+ $CRIT8  \+ $CRIT9  \+ $CRIT10`
CTRL[2]=10
ERROR[2]="MOLECULAR GEOMETRY NOT READ CORRECTLY"

# Nuclear repulsion energy:
CRIT1=`$GREP "Nuclear repulsion energy : * 9.0550045256" $log | wc -l`
TEST[3]=`expr $CRIT1`
CTRL[3]=1
ERROR[3]="NUCLEAR REPULSION ENERGY NOT CORRECT"

# Wave function:
CRIT1=`$GREP "Number of closed shell electrons * 10" $log | wc -l`
CRIT2=`$GREP "Number of electrons in active shells * 0" $log | wc -l`
CRIT4=`$GREP "Total number of orbitals * 24" $log | wc -l`
CRIT5=`$GREP "Spin multiplicity .* 1" $log | wc -l`
CRIT6=`$GREP "Total number of symmetries * 4" $log | wc -l`
CRIT7=`$GREP "Reference state symmetry * 1" $log | wc -l`
TEST[4]=`expr $CRIT1  \+ $CRIT2  \+ $CRIT4  \+ $CRIT5  \+ \
              $CRIT6  \+ $CRIT7`
CTRL[4]=6
ERROR[4]="INCORRECT WAVE FUNCTION"

# SCF energy:
CRIT1=`$GREP "Hartree-Fock total  *energy *: * \-76\.332196" $log | wc -l`
TEST[5]=`expr $CRIT1`
CTRL[5]=1
ERROR[5]="HF-srPBE ENERGY NOT CORRECT"

# MP2 energy:
# new numbers 14-feb-2010:
#  MP2 contribution from short-range integrals :            -0.1403388860
#  MP2 contribution from short-range integrals :            -0.2068793093
#  MP2 contribution from  long-range integrals :            -0.0024695881
#  MP2 contribution from  long-range integrals :            -0.0027576441 !!!!!
#  MP2 contribution from       sr-lr integrals :            -0.0248653481
#  MP2 contribution from sr-sr+sr-lr integrals :            -0.1652042341
#  MP2 contribution from        full integrals :            -0.1676738222
#  MP2 contribution from       sr-lr integrals :            -0.0297343951
#  MP2 contribution from sr-sr+sr-lr integrals :            -0.2366137044
#  MP2 contribution from        full integrals :            -0.2393713485
# old numbers:
#   MP2 contribution from short-range integrals :            -0.1403388860
#   MP2 contribution from short-range integrals :            -0.2068793093
# + MP2 contribution from long-range integrals  :            -0.0024695881
# + MP2 contribution from  long-range integrals :            -0.0027576412
#CRIT1=`$GREP "MP2 second order .* energy *: * \-76\.3349496" $log | wc -l`
#CRIT2=`$GREP "MP2 second order .* energy *: * \-76\.3349545" $log | wc -l`
CRIT1=`$GREP "MP2 contribution .* short-range .* \-0*\.140338" $log | wc -l`
CRIT2=`$GREP "MP2 contribution .* short-range .* \-0*\.206879" $log | wc -l`
CRIT3=`$GREP "MP2 contribution .* long-range .* \-0*\.002469" $log | wc -l`
CRIT4=`$GREP "MP2 contribution .* long-range .* \-0*\.0027576" $log | wc -l`
TEST[6]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`  # 1 + 1 + 1 + 1
CTRL[6]=4
ERROR[6]="MP2-srPBE ENERGY NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5 6
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo ${ERROR[i]} ' ( ' ${TEST[i]} ${CTRL[i]} ' )'
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
